package com.drcoffee.drcoffeemall.controller;

import com.drcoffee.drcoffeemall.entry.CssOrientation;
import com.drcoffee.drcoffeemall.entry.Explosion;
import com.drcoffee.drcoffeemall.entry.Machine;
import com.drcoffee.drcoffeemall.service.ExplosionService;
import com.drcoffee.drcoffeemall.util.BodyToMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 爆炸图
 *
 * @author ShiHao Zhou
 */
@RestController
@RequestMapping("/explosion")
public class ExplosionController {

    @Autowired
    ExplosionService explosionService;


    /*
     * 添加爆炸图
     * */
    @PostMapping("/insertData")
    public ResponseEntity<Object> insertData(@RequestParam("file") MultipartFile file, @RequestParam("file_name") String file_name, @RequestParam("explosion") String explosion) throws IOException {
        return explosionService.insertData(file, file_name, BodyToMapUtil.convertJsonToMap(explosion));
    }


    /*
     * 根据机器ID查询爆炸图
     * */
    @GetMapping("/getExplosionByMachineId")
    public ResponseEntity<Object> getExplosionByMachineId(@RequestParam Integer machine_id) {
        return explosionService.getExplosionByMachineId(machine_id);
    }

    /*
     * 根ID查询爆炸图
     * */
    @GetMapping("/getExplosionById")
    public Map<String, Object> getExplosionById(@RequestParam Integer id) {
        return explosionService.getExplosionById(id);
    }

    /*
     * 添加爆炸图圆点定位
     * */
    @GetMapping("/addCssOrientation")
    public Map<String, Object> addCssOrientation(@RequestParam Integer explosion_id) {
        System.out.println(explosion_id);
        return explosionService.addCssOrientation(explosion_id);
    }

    /*
     * 修改爆炸图圆点定位
     * */
    @PostMapping("/setCssOrientation")
    public Map<String, Object> setCssOrientation(@RequestBody CssOrientation cssOrientation) {
        return explosionService.setCssOrientation(cssOrientation);
    }

    /*
     * 查询包插图关联的定位点
     * */
    @GetMapping("/getCssOrientation")
    public Map<String, Object> getCssOrientation(@RequestParam Integer id) {
        return explosionService.getCssOrientation(id);
    }

    /*
     * 删除定位点
     * */
    @GetMapping("/deleteCssOrientation")
    public Map<String, Object> deleteCssOrientation(@RequestParam Integer id) {
        return explosionService.deleteCssOrientation(id);
    }

    /*
     * 定位点绑定配件
     * */
//    @GetMapping("/bindPart")
//    public Map<String, Object> bindPart(@RequestParam Integer dot_id, @RequestParam Integer attachment_id) {
//        return explosionService.bindPart(dot_id, attachment_id);
//    }
    /*
     * 定位点绑定配件
     * */
    @GetMapping("/bindPart")
    public ResponseEntity<Object> bindPart(@RequestParam Integer dot_id, @RequestParam List<String> attachments) {
        return explosionService.bindPart(dot_id, attachments);
    }


    /*
     * 定位点取消分解
     * */
    @GetMapping("/setDismantleN")
    public Map<String, Object> setDismantleN(@RequestParam Integer id) {
        return explosionService.setDismantleN(id);
    }

    /*
     * 添加爆炸图
     * */
    @PostMapping("/addExplosion")
    public Map<String, Object> addExplosion(@RequestBody Explosion explosion) {
        return explosionService.addExplosion(explosion);
    }

    /*
     * 图片上传
     * */
//    @PostMapping("/fileUpload")
//    public Map<String, Object> fileUpload(@RequestParam("file") MultipartFile file,
//                                          @RequestParam("name") String name,
//                                          @RequestParam("machine_id") Integer machine_id
//    ) throws IOException {
//        return explosionService.fileUpload(file, name, machine_id);
//    }


    /*
     * 删除爆炸图
     * */
    @PostMapping("/deleteExplosion")
    public Map<String, Object> deleteExplosion(@RequestBody Explosion explosion) {
        return explosionService.deleteExplosion(explosion);
    }

    /*
     * 设置定位点关联的分解图
     * */
    @GetMapping("/dotSetExplosion")
    public ResponseEntity<Object> dotSetExplosion(@RequestParam Integer id, @RequestParam Integer decompose_id) {
        return explosionService.dotSetExplosion(id, decompose_id);
    }


}
